package org.xhnews.ui;

import java.util.Vector;

import net.rim.device.api.ui.component.CheckboxField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.decor.BackgroundFactory;

import org.xhnews.bo.ForwardBo;
import org.xhnews.to.Contact;

public class ContactsSelectionScreen extends MainScreen {
	private TitleField _tf;
	private String[] _strContacts;
	private Vector _contacts;
	private CheckboxField[] cf;
	private ScreenClosedListener listener;
	public ContactsSelectionScreen(ScreenClosedListener listener) {
		this.listener = listener;
		_tf = new TitleField();
		_tf.setText("新闻转发");
		this.getMainManager().setBackground(
				BackgroundFactory.createLinearGradientBackground(0x0099CCFF,
						0x0099CCFF, 0x00336699, 0x00336699));
		_contacts = ForwardBo.getAllContacts();
		_strContacts = new String[_contacts.size()];
		cf = new CheckboxField[_contacts.size()];
		for (int i = 0; i < _strContacts.length; i++) {
			CheckboxField contact = new CheckboxField();
			contact.setLabel(((Contact) _contacts.elementAt(i)).getName());
			contact.setChecked(false);
			cf[i] = contact;
			add(contact);
		}
	}

	public Vector getSelectedUser() {
		Vector v = new Vector();
		for (int i = 0; i < cf.length; i++) {
			if (((CheckboxField) cf[i]).getChecked() == true) {
				v.addElement(_contacts.elementAt(i));
			}
		}
		return v;
	}

	protected void onUndisplay() {
	       listener.notifyScreenClosed(this);
	    } 
	protected boolean onSavePrompt() {
		return true;
	}
}
